// Register replace_continue_markup
BloggerExt.replace_continue_markup = function() {
    // make continue...
	if(BloggerExtOptions.replace_continue_markup_animate) {
		var animate_str = "'fast',";
	}else {
		var animate_str = ").each(";
	}
    if( BloggerExt.isListMode() ) {
        jQuery('div.post-body').contains('##CONTINUE##').each( function (i) {
            if (BloggerExtOptions.replace_continue_markup_as_link) {
                var postSummaryLength =  jQuery(this).html().indexOf('##CONTINUE##');
                var postLinkHtml = "<span class='post-body-continue'><a href='"
                                  +jQuery(this).parent().find('.post-title a').attr('href')
                                  +"'>"+BloggerExtOptions.continue_markup_expand_title+"</a></span>";
                jQuery(this).html( jQuery(this).html().substr(0, postSummaryLength) + postLinkHtml );
            }else {
                var postLinkHtml = "<span class=\"post-body-continue\"><a id=\"post-body-toggle" + i + "\" onclick=\"jQuery('#post-body-hide"
                                  +i+"').toggle("+animate_str
								  +"function(){"
								  +"  jQuery(this).is(':hidden') ?"
                                  +"    jQuery('#post-body-toggle"+i+"').html(BloggerExtOptions.continue_markup_expand_title) : "
                                  +"    jQuery('#post-body-toggle"+i+"').html(BloggerExtOptions.continue_markup_collapse_title)"
                                  +"});\">"+BloggerExtOptions.continue_markup_expand_title+"</a></span>"
                                  +"<div style='display:none' id='post-body-hide"+i+"'>";
                jQuery(this).html( (jQuery(this).html().replace(/##CONTINUE##/g, postLinkHtml)) + "</div>");
            }
        });

    }else {
        jQuery('div.post-body').contains('##CONTINUE##').each( function (i) {
            jQuery(this).html(jQuery(this).html().replace(/##CONTINUE##/g,""));
        });
    }

    // support make continue by classname fullpost ...
    if( BloggerExt.isListMode() ) {
        // some bugfix jQuery('#fullpost') only return first match ?? why?? change to css selector mode.
        jQuery('div.post-body').each( function (i) {
            if( jQuery(this).find('#fullpost').length == 1 ) {
                if (BloggerExtOptions.replace_continue_markup_as_link) {
                    var postLinkHtml = "<span class='post-body-continue'><a href='"
                                      +jQuery(this).parent().find('.post-title a').attr('href')
                                      +"'>"+BloggerExtOptions.continue_markup_expand_title+"</a></span>";
                    jQuery(this).find('#fullpost').before( jQuery(postLinkHtml) ).remove();

                }else {
                    var postLinkHtml = "<span class=\"post-body-continue\"><a id=\"post-body-toggle" + i + "\" onclick=\"jQuery('.post-body-hide"
                                      +i+"').toggle("+animate_str
									  +"function(){"
									  +"  jQuery(this).is(':hidden') ? "
                                      +"    jQuery('#post-body-toggle"+i+"').html(BloggerExtOptions.continue_markup_expand_title) : "
                                      +"    jQuery('#post-body-toggle"+i+"').html(BloggerExtOptions.continue_markup_collapse_title)"
                                      +"});\">"+BloggerExtOptions.continue_markup_expand_title+"</a></span>";
                    jQuery(this).find('#fullpost').before( jQuery(postLinkHtml) ).addClass("post-body-hide"+i).css('display', 'none');
                }
            }
        });
    }else {
        jQuery('div.post-body #fullpost').each( function (i) {
                jQuery(this).show();
        });
    }
};

BloggerExt.register('replace_continue_markup' ,  {
    replace_continue_markup: true,
	replace_continue_markup_version: 1.0,
	replace_continue_markup_animate: false,
    replace_continue_markup_as_link: false,
    continue_markup_expand_title: '[+] Read More....',
    continue_markup_collapse_title: '[-] Summary....'
});
BloggerExt.registerHook(BloggerExt.replace_continue_markup);

